xen/arm: p2m: Remove translation table when it's empty
authorJulien Grall <julien.grall@citrix.com>
Tue, 1 Dec 2015 17:52:12 +0000 (17:52 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 15 Dec 2015 11:59:04 +0000 (11:59 +0000)
commitde5162b664ea3dea07a0b77b523413c2ce479f2a
tree7266c38000a1473222e429401611f18f02189386
parent47f43d1645c8751240415de8609a4c4b07ea3591
xen/arm: p2m: Remove translation table when it's empty

Currently, the translation table is left in place even if no entries
are in use. Because of how the p2m code has been implemented,
replacing a translation table by a block (i.e superpage) is not
supported. Therefore, any remapping of a superpage size will be split
in smaller chunks making the translation less efficient.

Replacing a table by a block when a new mapping is added would be too
complicated because it requires us to check if all the upper levels
are not in use and free them if necessary.

Instead, we will remove the empty translation table when mappings are
removed. To avoid going through all the table checking if no entry is
in use, a counter representing the number of entry currently in use is
kept per table translation and updated when an entry changes state
(i.e valid <-> invalid).

As Xen allocates a page for each translation table, it's possible to
store the counter in the struct page_info. A new field p2m_refcount
has been introduced in the in use union for this purpose. This is fine
as the page is only used by the P2M code and nobody touches the other
field of the union type_info.

For the record, type_info has not been used because it would require
more work to use it properly as Xen on ARM doesn't yet have the
concept of type.

Once Xen has finished removing a mapping and all the references to
each translation table have been updated, then the higher levels will
be processed and freed as needed. This will allow us to propagate the
number of references and free multiple translation table at different
level in one go.

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
[ ijc -- updated commit message as discussed ]
xen/arch/arm/p2m.c
xen/include/asm-arm/mm.h